package cn.itlaobing.web.servlet;


import cn.itlaobing.entity.VegetablesDTO;
import cn.itlaobing.exception.BusinessException;
import cn.itlaobing.service.VegetableService;
import cn.itlaobing.util.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Description:
 * @Author: WangDong
 * @Date: 2017/11/13 8:47
 */
@WebServlet("/index")
public class QueryServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        PageUtil pageUtil=new PageUtil();
        VegetableService vegetableService=new VegetableService();
        pageUtil.setRecordCount(10);
        String strPageIndex=request.getParameter("pageIndex");
        if(strPageIndex!=null && !strPageIndex.equals("")){
            pageUtil.setPageIndex(Integer.parseInt(strPageIndex));
        }
        try {
            // List<VegetablesDTO> list=vegetableService.findAll(pageUtil.getPageIndex(),pageUtil.getPageSize());
            List<VegetablesDTO> list=vegetableService.queryAll();
            System.out.println(list.size());
            request.setAttribute("pageUtil",pageUtil);
            request.setAttribute("DATAS",list);
            response.sendRedirect(request.getContextPath()+"/record.jsp");
        } catch (BusinessException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
